uniapp之防抖

您所在的位置:网站首页 uniapp settimeout uniapp之防抖

uniapp之防抖

2023-05-13 23:37| 来源: 网络整理| 查看: 265

一定时间点击提交按钮多次只触发一次

在utils文件夹下新建debounce.js文件,内容如下:

export const Debounce = (fn, wait) => { let delay = wait|| 500 let timer return function () { let args = arguments; if (timer) { clearTimeout(timer) } let callNow = !timer timer = setTimeout(() => { timer = null }, delay) if (callNow) fn.apply(this, args) } }

页面中使用

提 交 import {Debounce} from '@/utils/debounce.js' export default { data() { return {} }, methods: { //提交 submitFeedback:Debounce(function(e) { let _this = this; this.$api.submitQuestion({ emphasisNameId: this.emphasisName.id, syncId: uni.getStorageSync('sync_id') }, res => { if (res.code == 0) { this.isComplete = true; _this.openMpopup('success', '提交成功', 1500); } else { _this.openMpopup('err', res.msg, 1500); } }) },1000) } }


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3